<template>
  <div>
    <el-form ref="formData" :model="formData" status-icon>
      <el-form-item
        label="检测费用"
        :label-width="formLabelWidth"
        prop="detectionPrice"
      >
        <span>{{ stringPriceFormat(formData.detectionPrice) }}</span>
      </el-form-item>
      <el-form-item
        label="折扣方式"
        :label-width="formLabelWidth"
        prop="discountTypeCode"
      >
        <el-radio
          v-model="formData.discountTypeCode"
          :label="1"
          :disabled="readOnly"
          >协议价格</el-radio
        >
        <el-radio
          v-model="formData.discountTypeCode"
          :label="2"
          :disabled="readOnly"
          >整单折扣</el-radio
        >
      </el-form-item>
      <el-form-item
        label="折扣设置"
        :label-width="formLabelWidth"
        prop="discountTypeCode"
      >
        <div v-if="formData.discountTypeCode === 1">
          <el-button
            type="primary"
            style="width: 50%"
            @click="choiceAgreementPrice"
            >查看协议价</el-button
          >
        </div>
        <div v-if="formData.discountTypeCode === 2">
          折扣率:
          <el-input
            v-model="formData.discount"
            style="width: 31%"
            :disabled="readOnly"
            :controls="false"
            :precision="2"
            :min="0"
            :max="100000000"
          ></el-input>
          <span>%</span>
        </div>
      </el-form-item>

      <el-form-item
        label="优惠价"
        :label-width="formLabelWidth"
        prop="favorablePrice"
      >
        <span>{{ stringPriceFormat(formData.favorablePrice) }} </span>
      </el-form-item>
      <el-form-item
        label="最终价"
        :label-width="formLabelWidth"
        prop="finalPrice"
      >
        <span> {{ stringPriceFormat(formData.finalPrice) }}</span>
      </el-form-item>
    </el-form>
    <ChoiceAgreementPriceDialog
      ref="ChoiceAgreementPriceDialog"
      v-model="agreementPriceVisible"
      :read-only-detection-item-price.sync="readOnlyDetectionItemPrice"
      :entrust-order-id.sync="entrustOrderId"
      :detection-item-data.sync="detectionItemData"
      @closeDialog="closeDialog"
    />
  </div>
</template>
<script>
import { stringPriceFormat } from "@/utils/StringFormat.js";
import {
  get,
  entrustOrderPriceVerifyPass,
  entrustOrderPriceVerifyReject,
} from "@/ModuleEntrust/api/EntrustManage/EntrustOrderPrice";
import ChoiceAgreementPriceDialog from "@/ModuleEntrust/views/EntrustManage/EntrustOrderPrice/ChoiceAgreementPriceDialog.vue";

export default {
  name: "AuditEntrustOrderPriceAuditDetails",
  components: {
    ChoiceAgreementPriceDialog,
  },
  props: {
    fromSource: {
      type: String, // 数组 // 对象或数组默认值必须从一个工厂函数获取
      default: "",
    },
    editId: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      detectionItemData: [],
      entrustOrderId: "",
      readOnly: true,
      agreementPriceVisible: false,
      readOnlyDetectionItemPrice: true,
      formData: {
        id: "",
        entrustOrderId: "",
        detectionPrice: "",
        discountTypeCode: "",
        agreementPrice: "",
        discount: "",
        favorablePrice: "",
        finalPrice: "",
        pricelStatusCode: 1,
        entrustOrderDetectionItemPriceDtos: [],
      },
      formLabelWidth: "100px",
    };
  },
  watch: {
    // 开始监听返回该对象属性值计算属性
    editId: function(newVal, oldVal) {
     get({ Id: this.editId })
        .then((res) => {
          this.formData = res.data;
        });
    },
  },
  created() {
    get({ Id: this.editId })
      .then((res) => {
        this.formData = res.data;
      });
  },
  methods: {
    stringPriceFormat,
    // 选择协议价
    choiceAgreementPrice() {
      this.detectionItemData = this.formData.entrustOrderDetectionItemPriceDtos;
      this.entrustOrderId = this.formData.entrustOrderId;
      this.agreementPriceVisible = true;
    },
    closeDialog() {
      this.agreementPriceVisible = false;
    },

    innerPass(obj) {
     entrustOrderPriceVerifyPass(obj)
        .then((res) => {
          this.$emit("passOrNoPassEmit");
        })
        .catch();
    },
    innerWithdraw(obj) {
      obj.auditStatus = 60;
     entrustOrderPriceVerifyReject(obj)
        .then((res) => {
          this.$emit("passOrNoPassEmit");
        })
        .catch();
    },
    innerReject(obj) {
      entrustOrderPriceVerifyReject(obj)
        .then((res) => {
          this.$emit("passOrNoPassEmit");
        })
        .catch();
    },
  },
};
</script>

